<%@ LANGUAGE="VBSCRIPT" %>
<%
	'response.write Session("VanBan")
	if Instr(Session("VanBan"),"-"& request("bMa") &"-")=0 or Session("VanBan")="" then
		Response.Redirect(Session("URL")& "Error.asp?ErrorCode=3")
	end if
	Session("Attach")=""
%>
<!--#include file="..\RootContent.inc"-->
<!--#include file="..\CheckSession.inc"-->
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<%	
	bFileName=request("Filename")
	Set File = Server.CreateObject("ActiveFile.File")
	bMa=Request("bMa")
	bDatao=Request("bDatao")
	Path=RootContent & "Data\yeucau\TEXT\" & bMa & ".VT"
	File.Name=Path
	Dim KQ
	Set ClsF=server.CreateObject("Vinalines.ClsFunction")
	maflow=clsf.Giaima(request("Maflow"))	
	'*********Lay cac y kien truoc cho nguoi xu ly con**************************
	sSQL="Select * from flownode where maworkflowcon like '"& left(maflow,5) &"'"
	Set RecYK=server.CreateObject("ADODB.Recordset")
	RecYK.CursorType=3
	RecYK.CacheSize=5
	RecYK.Open sSQL,Conn
	'Lay cac ykien thuoc luong xu ly me
	if RecYK.RecordCount then
		Dim A 'Dua ra noi dung
		Call Report(A,RecYK("Maworkflownode"),"<table cellpadding=0 cellspacing bgcolor=#FFFFFF width='100%' ><tr><td  bgcolor=#FFFFFF>","")
		'Call Report(A,RecYK("Maworkflownode"),	"<table cellpadding=0 cellspacing width='100%' ><tr><td  >","")
		bOK=true		
	else
		bOK=false
	end if
	RecYK.Close
	Set RecYK=nothing
	'*********L&#7845;y &#253; ki&#7871;n trong lu&#7891;ng x&#7917; l&#253; hi&#7879;n t&#7841;i******************
	if bOK then		
		call report(KQ,maflow,"<table cellpadding=0 cellspacing bgcolor=#eeeecc width='100%' ><tr><td  bgcolor=#F8F9D9>","Xem n&#7897;i dung g&#7889;c")
		%><%=KQ%><%
		%><Table width='100%' bgcolor="#C0C0C0" cellpadding=0 cellspacing=0><TR><TD width='100%' align=center><font face=Arial color=white>
  Văn bản gốc và các ý kiến xử lý</font></TD></TR></Table><%
		%><%=A%><%
	else		
		call report(KQ,maflow,"<table cellpadding=0 cellspacing bgcolor=#eeeecc width='100%' ><tr><td  bgcolor=#F8F9D9>","Xem n&#7897;i dung g&#7889;c")
		%><%=KQ%>
		</td></tr></table>
		<Table width='100%' bgcolor="#C0C0C0" cellpadding=0 cellspacing=0><TR><TD width='100%' align=center><font face=Arial color=white>
          Văn bản gốc</font></TD></TR></Table>
	<%
	end if	
	Set ClsF=nothing
	'**************L&#7845;y n&#7897;i dung b&#7843;n g&#7889;c
	if File.Exists() then						
		Set ClsFile=server.CreateObject("Vinalines.ClsFile")
		bText=ClsFile.ReadTextFile(Path)
		sSQL="Select Tentep,mota from workflow_Tentep where MaWorkflow like '"& bMa &"'"
		Set RecT=server.CreateObject("ADODB.Recordset")
		RecT.CursorType=3
		RecT.CacheSize=5
		RecT.Open sSQL,Conn	
		if RecT.RecordCount then
			bAttach="<hr>"
			bAttach=bAttach & "<center><Table Width=100% border=1><TR bgcolor=#000080><TD Width=100% colspan=5 align=center><font face=Arial size=2 color=#FFFFFF><B><span >Danh s&#225;ch t&#224;i li&#7879;u g&#7855;n k&#232;m(B&#7845;m chu&#7897;t tr&#225;i &#273;&#7875; xem n&#7897;i dung/B&#7845;m chu&#7897;t ph&#7843;i &#273;&#7875; Download)</span></B></font></TD></TR></Table></center>"
			bAttach=bAttach & "<center><Table><TR>"
			bCol=0
			Do while not RecT.EOF
				if bCol=5 then
					bAttach=bAttach & "</TR><TR>"
					bCol=0
				end if
					bAttach=bAttach & "<TD Width=135 ><A href=OpenAttach.asp?filename="& Session("ClsFun").mahoa(lcase(RecT("Tentep"))) & " target=New><center>"
					imgext =lcase(ExtFile(RecT("Tentep")))
					select case imgext
						case "doc"
							bAttach=bAttach & "<IMG SRC="&"..\ImageAttach\doc.gif"&" border=0>"
						case "xls"
							bAttach=bAttach & "<IMG SRC="&"..\ImageAttach\xls.gif"&" border=0>"
						case "gif","jpg","bmp","tif"
							bAttach=bAttach & "<IMG SRC="&"..\ImageAttach\gif.gif"&" border=0>"
						case "txt","log","bat"
							bAttach=bAttach & "<IMG SRC="&"..\ImageAttach\txt.gif"&" border=0>"
						case "html","htm"
							bAttach=bAttach & "<IMG SRC="&"..\ImageAttach\html.gif"&" border=0>"
						case "ppt"
							bAttach=bAttach & "<IMG SRC="&"..\ImageAttach\ppt.gif"&" border=0>"
						case "pdf"
							bAttach=bAttach & "<IMG SRC="&"..\ImageAttach\pdf.gif"&" border=0>"
						case "mdb"
							bAttach=bAttach & "<IMG SRC="&"..\ImageAttach\mdb.gif"&" border=0>"
						case "com","exe"
							bAttach=bAttach & "<IMG SRC="&"..\ImageAttach\exe.gif"&" border=0>"
						case "avi"
							bAttach=bAttach & "<IMG SRC="&"..\ImageAttach\avi.gif"&" border=0>"
						case else
							bAttach=bAttach & "<IMG SRC="&"..\ImageAttach\other.gif"&" border=0>"
					end select
					bAttach=bAttach & "<br><font face=Arial size=2>" & RecT("Mota") & "</font></center></A></TD>"
				if  Session("Attach")="" then
					Session("Attach")="-" & RecT("Tentep")
				else
					Session("Attach")=Session("Attach") & "-" & RecT("Tentep")
				end if
				RecT.MoveNext
				bCol=bCol+1
			Loop
			Session("Attach")=Session("Attach") & "-" 
			bAttach=bAttach & "</TR></Table></center>"
		end if
		Set ClsFile=nothing
		%><Title>Hệ Quản Trị Văn Thư</Title>
		<Body style="font-family:Times New Roman ; font-size:12pt" topmargin=0 leftmargin=0 rightmargin=0>
			<%if Request("bXuly")="ok" then
			end if%>
			<%=bText%><%=bAttach%>
			<%if len(trim(bText))>2 then%>
				<p align=right><a href="#top"><FONT FACE=Arial size=2>Trở về đầu trang</font></a>
			<%end if%>
	</Body><%
	else
		Response.Write("&nbsp;")
		Response.Write("&nbsp;")
		Response.Write("&nbsp;")
		Response.Write("&nbsp;")
		Txt="<Body style='font-family:Arial' topmargin=0 leftmargin=0 rightmargin=0>"
		Response.Write(Txt)
		Txt="<p align=center><Font face=Arial size=4 color=red>V&#259;n th&#432; n&#224;y ch&#432;a c&#243; n&#7897;i dung</font></p>"
		Response.Write(Txt)
		Txt="</Body>"		
	end if
	Set File = Nothing
%>
<Script language=vbscript runat=server>
Function ExtFile(filename)
	dim longfilename
	dim VtCham
	longfilename=len(filename)
	VtCham=instr(1,filename,".")
	if VtCham>0 then
		ExtFile=mid(filename,VtCham+1,longfilename-VtCham)
	end if
End Function
Function Report(ByRef Kq, ByVal bMa, ByVal bNoidung,bText)
	    Set Rec=server.CreateObject("ADODB.Recordset")
	    Rec.CursorType=3
	    Rec.CacheSize=5
	    vtri = ItemLast(bMa)
	    Item = Left(bMa, (vtri - 1) * 2 + 5)
	    bcha = Left(Item, Len(Item) - 2)
	    bSosanh = bcha
	    For i = Len(bcha) + 1 To 23
	        bSosanh = bSosanh & "0"
	    Next
	    sSQL = "SELECT Hovaten,ykien,yeucauxl,Maworkflowcon FROM  Canbo INNER JOIN FlowNode ON dbo.Canbo.Macanbo = FlowNode.Nguoixuly where maworkflownode like '" & bSosanh & "'"
	    Rec.CursorType = 3
	    Rec.CacheSize = 5
	    Rec.Open sSQL, Conn
	    ok=false
	    If Rec.RecordCount Then
	        'Noidung = Rec("ykien")
			Set ClsNodeFile=server.CreateObject("Vinalines.ClsFile")
			bNodeFile=RootContent & "Data\Xuly\Text\" & trim(bSosanh ) & ".VT"
			Noidung = ClsNodeFile.ReadTextFile(bNodeFile)
			Set ClsNodeFile=nothing
	        ten = Rec("hovaten")
	        yeucauxl=Rec("yeucauxl")
	        ok=true
	        if isnull(Rec("Maworkflowcon")) then
		bNull=true
	        else
		bNull=false
		bMaW=Rec("Maworkflowcon")
	        end if
	    End If
	    Rec.Close	    
	    If vtri > 2 Then
		if yeucauxl<>"2" then
			if bNull then
				Temp = bNoidung &  "<font face=Arial color=blue size=3>" & ten & "</font></TD><TD bgcolor=#F8F9D9><p align=right><a name='top' href='#noidungoc'>"& bText &"</a></TD></TR><TR><TD colspan=2><pre  style='font-family:Arial;'>" &Noidung & "</pre></td></tr><tr><td bgcolor=#eeeecc height=2  ></td></tr><tr><td   bgcolor=#F8F9D9>"				
				Kq = Temp
			else
				Noidung=Tonghop(bMaW)				
				Temp = bNoidung &  "<font face=Arial color=blue size=3>" & ten & "(&#208;&#227; chuy&#7875;n cho nh&#7919;ng ng&#432;&#7901;i sau x&#7917; l&#253;)</font></TD><TD bgcolor=#F8F9D9><p align=right><a name='top' href='#noidungoc'>"& bText &"</a></TD></TR><TR><TD colspan=2><pre  style='font-family:Arial;'>" &Noidung & "</pre></td></tr><tr><td bgcolor=#eeeecc height=2  ></td></tr><tr><td   bgcolor=#F8F9D9>"			
				Kq = Temp
			end if
		else
			if bNull then
				Temp = bNoidung &  "<font face=Arial color=blue size=3>" & ten & "</font></TD><TD bgcolor=#F8F9D9><p align=right><a name='top' href='#noidungoc'>"& bText &"</a></TD></TR><TR><TD colspan=2><pre  style='font-family:Arial;'>&#208;&#227; xem</pre></td></tr><tr><td bgcolor=#eeeecc height=2  ></td></tr><tr><td   bgcolor=#F8F9D9>"				
				Kq = Temp
			else
				Noidung=Tonghop(bMaW)				
				Temp = bNoidung &  "<font face=Arial color=blue size=3>" & ten & "(&#208;&#227; chuy&#7875;n cho nh&#7919;ng ng&#432;&#7901;i sau Xem)</font></TD><TD bgcolor=#F8F9D9><p align=right><a name='top' href='#noidungoc'>"& bText &"</a></TD></TR><TR><TD colspan=2><pre  style='font-family:Arial;'>&#208;&#227; xem</pre></td></tr><tr><td bgcolor=#eeeecc height=2  ></td></tr><tr><td   bgcolor=#F8F9D9>"				
				Kq = Temp
			end if
		end if		
		Call Report(Kq, bcha, Temp,"")
	    else
		Temp = bNoidung &  "<font face=Arial color=blue size=3><a name=noidungoc></a></font></td><td bgcolor=#F8F9D9></td></tr><tr><td bgcolor=#F8F9D9></td></tr></Table>"		
		Kq = Temp
	    End If
End Function
Function Layten(bMa)
	Set RecLay=server.CreateObject("ADODB.Recordset")
	RecLay.CursorType=3
	RecLay.CacheSize=5
	sSQL="Select * from canbo where macanbo like '"& bMa &"'"	
	RecLay.Open sSQL,Conn
	if RecLay.RecordCount then
		Layten=RecLay("hovaten")
	end if
	RecLay.Close
	set RecLay=nothing
End function
Function Tonghop(bMa)
	sSQL="Select * from flownode where maworkflow like '"& bMa &"'"
	Set RecF=server.CreateObject("ADODB.Recordset")
	RecF.CursorType=3
	RecF.Open sSQL,Conn
	bTemp="<center><table width='90%' ><TR><TD width='90%'>"
	Do While not RecF.EOF		
		if RecF("yeucauxl")="1" then
			'bYkien=RecF("ykien")
			Set ClsNodeFile=server.CreateObject("Vinalines.ClsFile")
			bNodeFile=RootContent & "Data\Xuly\Text\" & trim(bMa) & ".VT"
			bYkien = ClsNodeFile.ReadTextFile(bNodeFile)
			Set ClsNodeFile=nothing
		else
			bYkien="&#208;&#227; xem "
		end if
		bTemp=bTemp+"<font face=Arial color=blue>"+Layten(RecF("Nguoixuly"))+"</font><pre style='font-family:Arial'>"+bYkien + "</pre></TD></TR><TR><TD ></TD></TR><TR><TD width='80%'>"
		RecF.MoveNext
	Loop
	Tonghop=bTemp + "</TD></TR></Table></center>"
	RecF.Close
	Set RecF=nothing
End Function
Function ItemLast(Item)
        Dim i
        Dim It
        Dim vt
        Dim j, Temp
        It = Item
        It = Right(It, Len(It) - 4)
        j = 1
        For i = 2 To Len(It)
            If i < Len(It) Then
                Temp = Mid(It, i, 1)
                i = i + 1
                Temp = Temp & Mid(It, i, 1)
                j = j + 1
                If Temp = "00" Then
                    ItemLast = j - 1
                    Exit For
                Else
                    If i = Len(It) Then
                        ItemLast = j
                    End If
                End If
            End If
        Next
    End Function
            </script>
</html>